<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>

  <script>
    // Promise用来封装异步操作

    // 创建promise对象
    const p = new Promise((resolve, reject) => { 
      // console.log('excutor()')
      
      // 执行异步操作
      setTimeout(() => {
        const isSuccess = Date.now()%2===1  // 奇数代表成功, 否则为失败
        if (isSuccess) { 
          resolve('成功的value数据')
        } else {
          reject('失败的reason数据')
        }
      }, 1000);
    })
    // console.log('new Promise之后')

    p.then( 
      value => {
        console.log('onResolved', value)
      },
      reason => {
        console.log('onRejected', reason)
      }
    )  

  </script>
</body>
</html>